<template>
	<h2>创建任务</h2><br />
	<el-form :model="task" label-width="120px">
		<el-form-item label="任务名称">
		      <el-input placeholder="请输入任务名称" v-model="task.taskName"/>  
		</el-form-item>
		<el-form-item label="任务内容">
			<el-input
			    v-model="task.taskContent"
			    :autosize="{ minRows: 3, maxRows: 8 }"
			    type="textarea"
			    placeholder="请输入任务内容"
			  />
		</el-form-item>
		<el-form-item label="任务完成日期">
			<el-date-picker
			v-model="task.taskDate"
			type="date"
			placeholder="请选择日期"
			:disabled-date="disabledDate"
			/>
		</el-form-item>
		
		<el-form-item label="任务优先级">
			<el-radio-group v-model="task.taskPriority">  
			      <el-radio label="低" size="large" border>低</el-radio>
			      <el-radio label="中" size="large" border>中</el-radio>
				  <el-radio label="高" size="large" border>高</el-radio>
			</el-radio-group>
		</el-form-item>
		
		
		<el-form-item label="分配人员">
			<el-select v-model="users" multiple placeholder="选择任务执行人员" style="width: 480px" >
			    <el-option  v-for="u in allUsers" :value="u.userId" :label="u.show" />
			</el-select>
		</el-form-item>
		
		
		<el-form-item>
		      <el-button type="primary" @click="submit">创建</el-button>
		      <el-button @click="cannel">取消</el-button>
		</el-form-item>
		
	</el-form>
	
</template>

<script>
	import qs from 'qs'
	export default {
		data(){
			return{
				task:{
					
				},
				users:[],
				allUsers:[],
				taskUser:{}
			}
		},
		methods:{
			submit(){
				let u=JSON.parse(sessionStorage.getItem("user"))
				this.task.userId=u.userId
				this.task.taskState='进行中'
				
				console.log(this.task)
				
				let that=this
				let str=qs.stringify(that.task)
				that.$axios.get("http://localhost:8080/task/taskcreat?"+str).then(function(res){
					for(let u1 in that.users ){
						that.taskUser.taskId=res.data
						that.taskUser.userId=that.users[u1]
						let s=qs.stringify(that.taskUser)
						that.$axios.get("http://localhost:8080/taskuser/creat?"+s).then(function(res){
							
						})
					}
				})
				
			},
			cannel(){
				this.$router.push("/index")
			},
			disabledDate(time) {
				return time.getTime() <= Date.now()
			}
		},
		created() {
			let that=this
			that.$axios.get("http://localhost:8080/user/createTask").then(function(res){
				that.allUsers=res.data
				let u
				for(u in that.allUsers){
					that.allUsers[u].show=that.allUsers[u].userName+" "+that.allUsers[u].userDepart
				}
				console.log(that.allUsers)
			})
		}
	}
	
</script>

<style>
</style>
